package utils;

import android.util.Log;

import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

import beans.StorageWarningInfoBean;
import beans.TimeoutBean;

/**
 * Created by Administrator on 2018/8/8.
 */

public class StockWarnSortUtils {

    /**
     * 物品
     * @param list
     * @param flag
     */
    public static void sortWarnGoods(List<StorageWarningInfoBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<StorageWarningInfoBean>() {
                @Override
                public int compare(StorageWarningInfoBean o1, StorageWarningInfoBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getGoodsName(), o1.getGoodsName()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getGoodsName(), o1.getGoodsName()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<StorageWarningInfoBean>() {
                @Override
                public int compare(StorageWarningInfoBean o1, StorageWarningInfoBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getGoodsName(), o1.getGoodsName()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getGoodsName(), o1.getGoodsName()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    /**
     * 供应商
     * @param list
     * @param flag
     */
    public static void sortWarnSupplier(List<StorageWarningInfoBean> list,boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<StorageWarningInfoBean>() {
                @Override
                public int compare(StorageWarningInfoBean o1, StorageWarningInfoBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getSupplier(), o1.getSupplier()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getSupplier(), o1.getSupplier()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<StorageWarningInfoBean>() {
                @Override
                public int compare(StorageWarningInfoBean o1, StorageWarningInfoBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getSupplier(), o1.getSupplier()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getSupplier(), o1.getSupplier()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }
//
//    /**
//     * 过期时间
//     * @param list
//     * @param flag
//     */
//    public static void sortWarn(List<StorageWarningInfoBean> list,boolean flag){
//
//        if (flag) {
//            Collections.sort(list, new Comparator<StorageWarningInfoBean>() {
//                @Override
//                public int compare(StorageWarningInfoBean o1, StorageWarningInfoBean o2) {
//                    long time1 = Long.parseLong(TimeUtil.dateToStamp(o1.getTimeoutDate()));
//                    long time2 = Long.parseLong(TimeUtil.dateToStamp(o2.getTimeoutDate()));
//                    if (time2 - time1 < 0) {
//                        return 1;
//                    } else if (time2 - time1 == 0) {
//                        return 0;
//                    } else {
//                        return -1;
//                    }
//                }
//            });
//        } else {
//            Collections.sort(list, new Comparator<StorageWarningInfoBean>() {
//                @Override
//                public int compare(StorageWarningInfoBean o1, StorageWarningInfoBean o2) {
//                    long time1 = Long.parseLong(TimeUtil.dateToStamp(o1.getTimeoutDate()));
//                    long time2 = Long.parseLong(TimeUtil.dateToStamp(o2.getTimeoutDate()));
//                    if (time2 - time1 > 0) {
//                        return 1;
//                    } else if (time2 - time1 == 0) {
//                        return 0;
//                    } else {
//                        return -1;
//                    }
//                }
//            });
//        }
//    }
//
//    /**
//     * 柜子
//     * @param list
//     * @param flag
//     */
//    public static void sortWarnCabinet(List<StorageWarningInfoBean> list,boolean flag){
//
//        if (flag) {
//            Collections.sort(list, new Comparator<StorageWarningInfoBean>() {
//                @Override
//                public int compare(StorageWarningInfoBean o1, StorageWarningInfoBean o2) {
//                    if (Integer.parseInt(o2.getCabinetCode()) - Integer.parseInt(o1.getCabinetCode()) < 0) {
//                        return 1;
//                    } else if (Integer.parseInt(o2.getCabinetCode()) - Integer.parseInt(o1.getCabinetCode()) == 0) {
//                        return 0;
//                    } else {
//                        return -1;
//                    }
//                }
//            });
//        } else {
//            Collections.sort(list, new Comparator<StorageWarningInfoBean>() {
//                @Override
//                public int compare(StorageWarningInfoBean o1, StorageWarningInfoBean o2) {
//                    if (Integer.parseInt(o2.getCabinetCode()) - Integer.parseInt(o1.getCabinetCode()) > 0) {
//                        return 1;
//                    } else if (Integer.parseInt(o2.getCabinetCode()) - Integer.parseInt(o1.getCabinetCode()) == 0) {
//                        return 0;
//                    } else {
//                        return -1;
//                    }
//                }
//            });
//        }
//    }
//
    /**
     * 规格
     * @param list
     * @param flag
     */
    public static void sortWarnSpecification(List<StorageWarningInfoBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<StorageWarningInfoBean>() {
                @Override
                public int compare(StorageWarningInfoBean o1, StorageWarningInfoBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getSpecification(), o1.getSpecification()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getSpecification(), o1.getSpecification()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<StorageWarningInfoBean>() {
                @Override
                public int compare(StorageWarningInfoBean o1, StorageWarningInfoBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getSpecification(), o1.getSpecification()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getSpecification(), o1.getSpecification()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }
//
    /**
     * 数量
     * @param list
     * @param flag
     */
    public static void sortWarnNumber(List<StorageWarningInfoBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<StorageWarningInfoBean>() {
                @Override
                public int compare(StorageWarningInfoBean o1, StorageWarningInfoBean o2) {
                    if (Integer.parseInt(o2.getNumber()) - Integer.parseInt(o1.getNumber()) > 0) {
                        return 1;
                    } else if (Integer.parseInt(o2.getNumber()) - Integer.parseInt(o1.getNumber()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<StorageWarningInfoBean>() {
                @Override
                public int compare(StorageWarningInfoBean o1, StorageWarningInfoBean o2) {
                    if (Integer.parseInt(o2.getNumber()) - Integer.parseInt(o1.getNumber()) < 0) {
                        return 1;
                    } else if (Integer.parseInt(o2.getNumber()) - Integer.parseInt(o1.getNumber()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    /**
     * 预警值
     * @param list
     * @param flag
     */
    public static void sortWarn(List<StorageWarningInfoBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<StorageWarningInfoBean>() {
                @Override
                public int compare(StorageWarningInfoBean o1, StorageWarningInfoBean o2) {
                    if (Integer.parseInt(o2.getWarnCount()) - Integer.parseInt(o1.getWarnCount()) > 0) {
                        return 1;
                    } else if (Integer.parseInt(o2.getWarnCount()) - Integer.parseInt(o1.getWarnCount()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<StorageWarningInfoBean>() {
                @Override
                public int compare(StorageWarningInfoBean o1, StorageWarningInfoBean o2) {
                    if (Integer.parseInt(o2.getWarnCount()) - Integer.parseInt(o1.getWarnCount()) < 0) {
                        return 1;
                    } else if (Integer.parseInt(o2.getWarnCount()) - Integer.parseInt(o1.getWarnCount()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }
}
